import fetch from 'common/src/utils/fetch';

function findStudentPlanList(data) {
    return fetch({
        url: '/api/cultureservice/bclCulturePlan/findStudentPlanList',
        method: 'post',
        data
    });
}

function findCultureSchemeList(data) {
    return fetch({
        url: '/api/cultureservice/bclCulturePlan/findCultureSchemeList',
        method: 'post',
        data
    });
}

function saveOrCommitPlan(data, params) {
    return fetch({
        url: '/api/cultureservice/bclCulturePlan/saveOrCommitPlanInfo/',
        // url: '/api/cultureservice/bclCulturePlan/saveOrCommitPlanInfo/' + params.type + '/' + params.studentID + '/' + params.schemeID + '/' +params.msg,
        method: 'post',
        data
    });
}

function chekCommit(data, params) {
    return fetch({
        url: '/api/cultureservice/bclCulturePlan/checkCommitInfo/',
        // url: '/api/cultureservice/bclCulturePlan/checkCommitInfo/' + params.type + '/' + params.studentID + '/' + params.schemeID,
        method: 'post',
        data
    });
}

function findPlanCourseTab(params) {
    return fetch({
        url: '/api/cultureservice/bclCulturePlan/findPlanCourseTab' + getParams(params),
        method: 'get'
    });
}

function addStudentCultureRelByManual(params) {
    return fetch({
        url: '/api/cultureservice/bclCulturePlan/blindScheme' + getParams(params),
        method: 'get'
    });
}

function cancelStudentCultureRelByManual(params) {
    return fetch({
        url: '/api/cultureservice/bclCulturePlan/cancelBlind' + getParams(params),
        method: 'get'
    });
}

function findSecondScheme(params) {
    return fetch({
        url: '/api/cultureservice/bclCulturePlan/findSecondScheme' + getParams(params),
        method: 'get'
    });
}

function saveSecondScheme(params) {
    return fetch({
        url: '/api/cultureservice/bclCulturePlan/saveSecondScheme' + getParams(params),
        method: 'get'
    });
}

// 培养计划审批撤回
function canCelCommit(params) {
    return fetch({
        url: '/api/cultureservice/bclCulturePlan/canCelCommit' + getParams(params),
        method: 'get'
    });
}

function findStudentInfo(params) {
    return fetch({
        url: '/api/cultureservice/bclCulturePlan/findStudentInfo' + getParams(params),
        method: 'get'
    });
}

function countCredit(params) {
    return fetch({
        url: '/api/cultureservice/bclCulturePlan/countCredit' + getParams(params),
        method: 'get'
    });
}

function findMadePlanCourseTab(params) {
    return fetch({
        url: '/api/cultureservice/bclCulturePlan/findMadePlanCourseList' + getParams(params),
        method: 'get'
    });
}

function isOpen(data) {
    return fetch({
        url: '/api/cultureservice/BclCulturePlanOpen/isOpen',
        method: 'post',
        data
    });
}

function exportMyCulturePlanPdf(data) {
    window.open('/api/cultureservice/bclCulturePlan/exportMyCulturePlanPdf' + getParams(data));
}

function getParams(params) {
    var paramsData = [];
    for (const key in params) {
        params[key] &&
            paramsData.push(
                key + '=' + params[key]
            );
    }
    if (paramsData.length)
        return '?' + paramsData.join('&');
    else
        return '';
}

const planManagementApi = {
    'findStudentPlanList': findStudentPlanList,
    'findCultureSchemeList': findCultureSchemeList,
    'saveOrCommitPlan': saveOrCommitPlan,
    'chekCommit': chekCommit,
    'addStudentCultureRelByManual': addStudentCultureRelByManual,
    'cancelStudentCultureRelByManual': cancelStudentCultureRelByManual,
    'findSecondScheme': findSecondScheme,
    'saveSecondScheme': saveSecondScheme,
    'canCelCommit': canCelCommit,
    'findStudentInfo': findStudentInfo,
    'countCredit': countCredit,
    'findPlanCourseTab': findPlanCourseTab,
    'findMadePlanCourseTab': findMadePlanCourseTab,
    'isOpen': isOpen,
    'exportMyCulturePlanPdf': exportMyCulturePlanPdf
}

export default planManagementApi;